package cn.wanda.bi.sunshine.platform.server.service.statistics;

import cn.wanda.bi.sunshine.platform.server.bean.mapper.A06727AppDailyPicareaFlowMapper;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppDailyPicareaFlow;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppDailyPicareaFlowExample;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.ListResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by pengjiang3
 */
@Service
public class A06727AppDailyPicareaService {

    public static final Logger logger = LoggerFactory.getLogger(A06727AppDailyPicareaService.class);

    @Autowired
    private A06727AppDailyPicareaFlowMapper mapper;

    @Cacheable(value="cache:statistics", key = "'cache:statistics:dailypicarea:starttime:'+#startTime+':endtime:'+#endTime+':index:'+#index+':limit:'+#limit")
    public ListResponse<A06727AppDailyPicareaFlow> dailyPicareaFlow(Long startTime, Long endTime, Integer index, Integer limit) {
        A06727AppDailyPicareaFlowExample example = new A06727AppDailyPicareaFlowExample();
        A06727AppDailyPicareaFlowExample.Criteria criteria = example.createCriteria();
        if (startTime != null && StringUtils.isNotEmpty(startTime + ""))
            criteria.andDatekeyGreaterThanOrEqualTo(new Date(startTime));
        if (endTime != null && StringUtils.isNotEmpty(endTime + ""))
            criteria.andDatekeyLessThanOrEqualTo(new Date(endTime));
        int count = mapper.countByExample(example);
        example.setOffset(index * limit - limit);
        example.setLimit(limit);
        example.setOrderByClause("datekey desc");
        List<A06727AppDailyPicareaFlow> appDailyPicareaFlows = mapper.selectByExample(example);
        return ListResponse.success(appDailyPicareaFlows, count, index, limit);
    }

}
